package recursion;

// 记忆化求斐波那契数列
public class Test01 {

    private static int[] data = new int[100];
    private static int count = 0;


    public static void main(String[] args) {
        int n = 20;
        System.out.println(fib(n));
        System.out.println(count);
    }

    private static int fib(int n) {
        count++;
        if(data[n] != 0){
            return data[n];
        }
        if(n == 1 || n ==2 ){
            data[n] = 1;
            return data[n];
        }
        data[n] = fib(n -1) + fib(n-2);
        return data[n];

    }
}
